<template>
  <div class="layout" @click="itemClick()">
    <div class="container">
      <div v-if="goodsCountMoreThanOne" class="img-container">
        <img  class="goods-pic" v-for="(imgUrl,index) in getImgList" v-lazy="imgUrl" :key="index"/>
      </div>
      <div v-else class="img-container" style="align-items: flex-start">
        <img class="goods-pic" v-lazy="item.goods[0].pic"/>
        <div class="flex-c" style="margin-left: 10px;margin-top: 2vw;align-items: flex-start">
          <span class="title" v-text="item.goods[0].name"></span>
          <span class="sub-title" v-text="item.goods[0].describe"></span>
        </div>
        <div style="flex: 1"></div>
      </div>
      <div class="flex-r">
        <img :src="getIcon('more')" style="width: 4vw" v-show="showEllipsis"/>
        <img :src="getIcon('arrow_right')" class="icon-right"/>
      </div>
    </div>
    <div class="divider" style="margin-top: 10px"></div>
    <div class="flex-r" style="width: 100vw;margin: 2vw 0">
      <span class="time" v-text="item.time"></span>
      <span class="total-price" v-text="getPrice"></span>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
  import Public from '@/assets/js/public';

  export default {
    /** kebab-case */
    name: 'item-order-default',

    data() {
      return {
        item: this.itemObj,
        orderImg: []
      };
    },
    /** 在声明 prop 的时候，其命名应该始终使用 camelCase，而在模板和 JSX 中应该始终使用 kebab-case。
     String/Number/Boolean/Function/Object/Array/Symbol */
    props: {
      itemObj: {
        required: true
      },
      index: {
        required: true,
        type: Number
      }
    },

    components: {},

    methods: {
      getIcon(icon) {
        return Public.ossImg + icon + '.svg';
      },
      itemClick() {
        this.$emit('onItemCLick', this.index);
      }
    },
    computed: {
      goodsCountMoreThanOne() {
        return this.item.goods.length > 1;
      },
      getPrice() {
        return '¥' + this.item.totalPrice;
      },
      getImgList() {
        let list = [];
        this.item.goods.forEach((good, index) => {
          if (index <= 2) {
            list.push(good.pic);
          }
        });
        return list;
      },
      showEllipsis() {
        return this.item.goods.length > 3;
      }
    },
    watch: {
      // 监听具体数据变化，并做相应的处理
    }
  };
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  @import "../../assets/stylus/main.styl";
  .flex-r
    flex-x()

  .flex-c
    flex-y()

  .center
    flex-center()

  .divider
    divider()

  .space
    space()

  .layout
    background-color white
    flex-y()
    margin-bottom 10px

  .container
    display flex
    flex-direction row
    justify-content space-between
    align-items center
    width 100vw
    padding-top 10px

  .img-container
    margin-left 10px
    width 84vw
    display flex
    flex-direction row
    justify-content space-around
    align-items center

  .icon-right
    width 5vw
    margin-right 10px
    margin-left 4px

  .goods-pic
    width 24vw
    /*height 24vw*/

  .time
    word-tip()
    margin-left 10px

  .total-price
    word-big()
    margin-right 10px

  .sub-title
    word-main()
    margin-top 1vw

  .title
    word-big()

  .img-wrapper[lazy=loading]{
    background third-ash
    width:100%;
    height: 10vw
  }

</style>
